博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
how to enable fileupload and button control after once uploading of images
阅读量:5049 次
发布时间:2019-06-12

本文共 4159 字,大约阅读时间需要 13 分钟。

<% @PageLanguage="C#"AutoEventWireup="true"CodeFile="FileuploadandButton.aspx.cs"Inherits="DataControl_FileuploadandButton" %> 
< htmlxmlns="http://www.w3.org/1999/xhtml">< headid="Head1"runat="server">< title>
< scripttype="text/javascript"> $(document).ready(function () { InitializeImageSlider();}); function InitializeImageSlider() { $( '.flexslider').flexslider({ animation: "slide", controlNav: false, directionNav: false, itemWidth: "120%", itemHeight: "50px", slideshowSpeed: 2000, }); }
  #divMessage {   height: 205px;   width: 347px;   top: 29px;   left: 375px;   position: absolute; }  #form1 {   height: 783px; }   img{max-width:100%; height:400px; display: block;} .style1 {   left: 448px;   top: 23px; }
 
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class DataControl_FileuploadandButton : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if(!IsPostBack)        {           LoadImage();        }    }        private void LoadImage()    {        try        {                       string imagePath = "~/BannerImage/";            string imageSource = SiteBaseUrl + "/BannerImage/";            string PhotoFilePath = Server.MapPath(imagePath);            string divSlider = @"
    "; string fileSlide = string.Empty; string fileName = string.Empty; DirectoryInfo di = new DirectoryInfo(PhotoFilePath); FileInfo[] rgFiles = di.GetFiles("*.*"); foreach (FileInfo fi in rgFiles) { fileSlide =@"
  • "; divSlider += fileSlide; } divImageSlider.InnerHtml = divSlider +"
"; } catch (Exception ex) { } } public static string SiteBaseUrl { get { string orginalUrl = HttpContext.Current.Request.Url.AbsoluteUri; if (HttpContext.Current.Request.Url.Query.Length > 0) orginalUrl = orginalUrl.Replace(HttpContext.Current.Request.Url.Query, string.Empty); return orginalUrl.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty) + (( HttpContext.Current.Request.ApplicationPath == "/" ?"" : HttpContext.Current.Request.ApplicationPath)) + '/'; } } public void UploadImage() { if (CheckValidImage(FileUpload2)) { FileUpload2.PostedFile.SaveAs(MapPath("~") + "/BannerImage/" + FileUpload2.FileName); ShowErrorMsg("success", "Image Uploaded Successfully"); LoadImage(); } } private bool CheckValidImage(FileUpload FileUploadImage) { string contentType; contentType = FileUploadImage.PostedFile.ContentType.ToLower(); if (contentType == "image/jpg" || contentType == "image/png" || contentType == "image/jpeg") { } else { ShowErrorMsg("error", "Image format is not valid. Valid image formats are ( jpg, png, jpeg)."); return false; } return true; } private void ShowErrorMsg(string _class, string _msg) { divMessage.Style.Value = "display:block;"; divMessage.Attributes.Add("class", _class); // divMessage.Attributes.Add("display", "block"); //divMessage.InnerHtml = _msg; Label test=new Label(); test.Text=_msg; divMessage.Controls.Add(test); } protected void btnsave_Click(object sender, EventArgs e) { } protected void btnUpload_Click(object sender, EventArgs e) { UploadImage(); }}

 FROM:

转载于:https://www.cnblogs.com/happy-Chen/p/3680052.html

你可能感兴趣的文章
sql 随笔
查看>>
Bootstrap多层模态框modal嵌套问题
查看>>
八大生物识别技术
查看>>
windows自带记事本导致文本文件(UTF-8编码)开头三个字符乱码问题
查看>>
Elasticsearch 基于 URL 的搜索请求
查看>>
Atitit. 最佳实践 QA----减少cpu占有率--cpu占用太高怎么办
查看>>
Android输入法扩展之外接键盘中文输入
查看>>
mybatis generator插件开发
查看>>
hibernate 多对多 最佳实践
查看>>
ios至于理解锚
查看>>
Windows下搭建Eclipse+Android4.0开发环境
查看>>
利用Excel批量高速发送电子邮件
查看>>
C#:总结页面传值几种方法
查看>>
HDU 1159 - Common Subsequence [最长公共子序列]
查看>>
Python学习总结
查看>>
CamShift算法研究(基于opencv)
查看>>
BF算法
查看>>
DataTable 基本转换简单实例
查看>>
IOS-下载动画
查看>>
一步步构建iOS路由
查看>>